package mosync.mobilelualiveditor;

import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class CheckboxController extends PropertyController
{
	public CheckboxController(String name)
	{
		super(name);
	}

	public String getCallbackTemplateHeader(String name)
	{
		return "function " + name + "_stateChanged(state)";
	}

	public JComponent createComponent()
	{
		final JCheckBox checkbox = new JCheckBox();

		// slider.setMaximumSize(new Dimension(5000, 32));
		checkbox.addChangeListener(new ChangeListener()
		{
			public void stateChanged(ChangeEvent e)
			{
				JCheckBox c = (JCheckBox) e.getSource();
				if (c == checkbox)
				{
					String value = "" + c.isSelected();
					String code = mName + "_stateChanged(" + value + ")\n";
					Evaluator.getSingleton().evaluate(code);
				}
			}
		});

		return checkbox;
	}
}